/***极速电话提问*/

$(function() {
	
	
	$(window).on("load", getInitOrderInfo);
	
	$('.question-fast').on("click", submitOrder);
	
	
	function SpeedPhoneOrder() {
		var speedPhoneOrder;
		speedPhoneOrder = utilModule.dealFormFilter("orderForm");
		return speedPhoneOrder;
	}
	
	
	//获取上一步提交的患者信息
	function getInitOrderInfo(){
		var orderKey = utilModule.getQueryString("key");
		if(utilModule.checkUndefined(orderKey) == "") {
			mui.alert("参数不能为空", "提示");
			return false;
		}
		var initOrderInfo = sessionStorage.getItem(orderKey);
		if(initOrderInfo != null) {
		    initOrderInfo = JSON.parse(initOrderInfo);
			$("#answerMobile").val(initOrderInfo.answerMobile);
			$("#patientName").val(initOrderInfo.patientName);
			$("#birthday").val(initOrderInfo.birthday);
			$("#patientSex").val(initOrderInfo.patientSex);
		}
	}
	
	//提交订单
	function submitOrder(){
		
	   var questionbody = $("#questionbody").val().replace(/\s+/g,""); 
	   if(questionbody.length<10||questionbody.length>1000){
			mui.alert("字数限定为10-1000个",'提示');
			return false;
		};
	    if(questionbody.length>10){
	    	$(".qword-num").hide();
	    };
	    
		var questionfilesObject=$("input[name='questionfiles']").length;
	    var questionfiles=""; 
	    $("input[name='questionfiles']").each(function(){
	    	questionfiles+=$(this).val()+",";
	    });
		
		//提交订单
		var speedPhoneOrder = SpeedPhoneOrder();
		speedPhoneOrder.patientId = USERID;
		speedPhoneOrder.openId = OPENID;
		speedPhoneOrder.questionfiles = questionfiles;
		speePhoneOrderModule.submitOrder(speedPhoneOrder, function(callBack) {
			var data = callBack;
			if(data != null) {
			   mui.toast("下单成功!");
			   location.replace("rapidly-order.html?orderid="+data)
			}
		});		
	}
	
	 
});